import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { EQuestionFuncCode } from "../../../../Message/Public/EQuestionFuncCode";
import { SQuestionFunc } from "../../../../Message/Public/SQuestionFunc";
import { SQuestionPrepareStart } from "../../../../Message/Public/SQuestionPrepareStart";
import { SQuestionData } from "../../../../Message/Public/SQuestionData";
import { SQuestionPlayerInfo } from "../../../../Message/Public/SQuestionPlayerInfo";
import { SSeqQuestionMark } from "../../../../Message/Public/SSeqQuestionMark";
type int = number;
//class QuestionDataTool
    
    export  class QuestionDataTool
    {
        

        public static setTimer(arg1: int): void
        {
            if (QuestionDataTool._secTimer == null) 
            {
                QuestionDataTool._secTimer = new SecTimer();
                QuestionDataTool._secTimer.addListener(TimerType.ENTERFRAME, QuestionDataTool.onTimerHandler);
                QuestionDataTool._secTimer.addListener(TimerType.COMPLETE, QuestionDataTool.onCompleteHandler);
            }
            QuestionDataTool.leftTime = arg1;
            QuestionDataTool._secTimer.reset();
            QuestionDataTool._secTimer.repeatCount = arg1;
            QuestionDataTool._secTimer.start();
            return;
        }

        /* internal  */static onTimerHandler(arg1: SecTimer): void
        {
            QuestionDataTool.leftTime = arg1.repeatCount;
            return;
        }

        /* internal  */static onCompleteHandler(arg1: SecTimer): void
        {
            arg1.stop();
            arg1.isDelete = false;
            QuestionDataTool.leftTime = 0;
            return;
        }

        public static isCorrect(): Boolean
        {
            var loc1=false;
            if (QuestionDataTool.selectAnswer != QuestionDataTool.sQuestionData.question.answer) 
            {
                loc1 = false;
            }
            else 
            {
                loc1 = true;
            }
            return loc1;
        }

        public static getCorrectAnswer(): string
        {
            if (!QuestionDataTool.sQuestionData) 
            {
                return "";
            }
            var loc1="";
            var loc2=QuestionDataTool.sQuestionData.question;
            var loc3=loc2.answer;
            if (loc3 != loc2.a) 
            {
                if (loc3 != loc2.b) 
                {
                    if (loc3 != loc2.c) 
                    {
                        if (loc3 == loc2.d) 
                        {
                            loc1 = loc2.d;
                        }
                    }
                    else 
                    {
                        loc1 = loc2.c;
                    }
                }
                else 
                {
                    loc1 = loc2.b;
                }
            }
            else 
            {
                loc1 = loc2.a;
            }
            return loc1;
        }

        public static get correctFuncTimes(): int
        {
            return QuestionDataTool.getFuncTimesByCode(EQuestionFuncCode._EQuestionFuncCodeRight);
        }

        public static get remainTwoFuncTimes(): int
        {
            return QuestionDataTool.getFuncTimesByCode(EQuestionFuncCode._EQuestionFuncCodeRemainTwo);
        }

        public static get doubleFuncTimes(): int
        {
            return QuestionDataTool.getFuncTimesByCode(EQuestionFuncCode._EQuestionFuncCodeDouble);
        }

        /* internal  */static getFuncTimesByCode(arg1: int): int
        {
            var loc1=null;
            var loc3=0;
            if (QuestionDataTool.sQuestionPlayerInfo == null) 
            {
                return 0;
            }
            var loc2=QuestionDataTool.sQuestionPlayerInfo.funcs;
            var loc4=0;
            while (loc4 < loc2.length) 
            {
                loc1 = loc2[loc4] as SQuestionFunc;
                if (arg1 == loc1.funcCode) 
                {
                    loc3 = loc1.totalTimes - loc1.usedTimes;
                    break;
                }
                ++loc4;
            }
            return loc3;
        }

        public static setWrongAnswer(): void
        {
            var loc1=QuestionDataTool.sQuestionData.question;
            var loc2=loc1.answer;
            if (loc2 == loc1.a) 
            {
                if (loc2 == loc1.b) 
                {
                    if (loc2 == loc1.c) 
                    {
                        if (loc2 != loc1.d) 
                        {
                            QuestionDataTool.selectAnswer = loc1.d;
                        }
                    }
                    else 
                    {
                        QuestionDataTool.selectAnswer = loc1.c;
                    }
                }
                else 
                {
                    QuestionDataTool.selectAnswer = loc1.b;
                }
            }
            else 
            {
                QuestionDataTool.selectAnswer = loc1.a;
            }
            return;
        }

        public static /* var */sQuestionPrepareStart: SQuestionPrepareStart;

        public static /* var */sQuestionData: SQuestionData;

        public static /* var */selectAnswer: string="";

        public static /* var */answerState: int=0;

        public static /* var */isStart: Boolean=false;

        public static /* var */sQuestionPlayerInfo: SQuestionPlayerInfo;

        public static /* var */isFuncUse: Boolean=false;

        public static /* var */timeStr: string="";

        public static /* var */haveAnswer: Boolean=false;

        public static /* var */questionMark: SSeqQuestionMark;

        /* internal */ static /* var */_secTimer: SecTimer;

        public static /* var */leftTime: int=0;

        public static /* var */functCode: int=-1;
    }

            QuestionDataTool.selectAnswer = "";
            QuestionDataTool.answerState = 0;
            QuestionDataTool.isStart = false;
            QuestionDataTool.isFuncUse = false;
            QuestionDataTool.timeStr = "";
            QuestionDataTool.haveAnswer = false;
            QuestionDataTool.leftTime = 0;
            QuestionDataTool.functCode = -1;
        